const { formatTime_chinese } = require("../../../../common/util/util")

Page({
    data: {
        ing: false,
        show: true,
        user: '',
        value: '',
        then: '',
        xReader: false
    },

    onLoad: function (options) {
        let that = this
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.on('acceptDataFromOpenerPage', function (data) {
            console.log(data)
            let xReader = data.item.quote_info.length > 0 ? false : true
            if(data.item.quote_info.length > 0){
                data.item.quote_info[0].create_time = formatTime_chinese(new Date(data.item.quote_info[0].create_time))
            }
            that.setData({
                user: data.item.from_user_info,
                then: data.item,
                xReader: xReader
            })
        })
    },

    xIng: function () {
        let that = this
        that.setData({
            ing: true,
            show: false
        })
    },

    xLook: function () {
        let that = this
        let show = that.data.show
        that.setData({
            show: !show
        })
    },

    xAe: function (e) {
        let params = e.currentTarget.dataset
        wx.navigateTo({
            url: '/subdter/pages/email/u-list/index?id=' + params.id +
                '&name=' + params.name + 
                '&number=' + params.number +
                '&ava=' + params.ava
            ,
        })
    },

    xInput: function (e) {
        let that = this
        console.log(e)
        let value = e.detail.value
        that.setData({
            value: value
        })
    },

    xSubmit: function () {
        wx.showLoading({
            title: '发送中',
            icon: 'none'
        })
        let that = this
        let value = that.data.value
        let user = that.data.user
        let then = that.data.then
        if (value === '') {
            wx.showToast({
                title: '您还未评价',
                icon: 'none'
            })
        } else {
            let _dataObj = {
                to_openid: user.user_id,
                quote_message_id: then._id,
                message_type: 1,
                business_type: 8,
                content: {
                    "title": "心理聊愈咨询师回复",
                    "content": {
                        "text": value,
                    }
                }
            }
            wx.cloud.callFunction({
                name: 'consulting_message',
                data: {
                    action: "send_message",
                    dataObj: _dataObj
                }
            }).then(res => {
                wx.hideLoading({
                    success: (res) => {
                        wx.navigateBack({
                            delta: 1,
                        })
                    },
                })
            })
        }
    }
})